package com.lc.rocketmq.dao;

import com.lc.rocketmq.po.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * @author liuc
 * @date 2021/8/21
 * @description
 **/
public interface OrderDao extends JpaRepository<Order,Long> {

    @Modifying
    @Query(nativeQuery = true,value = "update orders set status = ?2,last_update_time=now() where id = ?1 and status = ?3")
    int setStatus(Long orderId, int status, int old);

    @Modifying
    @Query(nativeQuery = true,value = "update orders set status = ?2,pay_time = now() where id = ?1 and status = ?3")
    int pay(Long orderId, int status, int old);

    @Query(nativeQuery = true, value = "select * from orders where user_id = ?1 and goods_id = ?2 and status < ?3")
    Order findByUserIdAndGoodsId(Long userId, Long goodsId, int status);
}
